/*    */ package cc.s2m.web.s2mBlog.freemarker;
/*    */ 
/*    */ import freemarker.template.SimpleNumber;
/*    */ import freemarker.template.SimpleScalar;
/*    */ import freemarker.template.TemplateBooleanModel;
/*    */ import freemarker.template.TemplateMethodModelEx;
/*    */ import freemarker.template.TemplateModelException;
/*    */ import java.util.List;
/*    */ 
/*    */ public class PageBar
/*    */   implements TemplateMethodModelEx
/*    */ {
/*    */   public Object exec(List arguments)
/*    */     throws TemplateModelException
/*    */   {
/* 15 */     if ((arguments == null) || (arguments.size() < 1)) {
/* 16 */       return "";
/*    */     }
/* 18 */     int totalPage = ((SimpleNumber)arguments.get(0)).getAsNumber().intValue();
/* 19 */     String url = ((SimpleScalar)arguments.get(1)).getAsString();
/* 20 */     boolean hasPrevPage = ((TemplateBooleanModel)arguments.get(2)).getAsBoolean();
/* 21 */     boolean hasNextPage = ((TemplateBooleanModel)arguments.get(3)).getAsBoolean();
/* 22 */     int curPage = ((SimpleNumber)arguments.get(4)).getAsNumber().intValue();
/* 23 */     if (totalPage < 2) {
/* 24 */       return "";
/*    */     }
/* 26 */     StringBuffer strBuf = new StringBuffer("<nav role=\"navigation\" class=\"pagination\">");
/* 27 */     if (hasPrevPage)
/* 28 */       strBuf.append("<span class=\"page-number\"><a href=\"" + url + "page/" + (curPage - 1) + "/\">prev</a></span>");
/*    */     else {
/* 30 */       strBuf.append("<span class=\"page-number\" style=\"background-color:#ccc;\">prev</span>");
/*    */     }
/* 32 */     int showPages = 6;
/* 33 */     int showPages_now = 1;
/* 34 */     int showPages_min = 1;
/* 35 */     int showPages_max = totalPage;
/* 36 */     StringBuffer pagesBuffer = new StringBuffer();
/* 37 */     pagesBuffer.append("<span class=\"page-number\" style=\"background-color:#f6bb87;\">" + curPage + "</span>");
/* 38 */     for (int i = 1; i <= showPages / 2; i++) {
/* 39 */       int curPage_tmp = curPage - i;
/* 40 */       if (curPage_tmp < 1) {
/*    */         break;
/*    */       }
/* 43 */       pagesBuffer.insert(0, "<span class=\"page-number\"><a href=\"" + url + "page/" + curPage_tmp + "/\">" + curPage_tmp + "</a></span>");
/* 44 */       showPages_now++;
/* 45 */       showPages_min = curPage_tmp;
/*    */     }
/* 47 */     for (int i = 1; i <= showPages / 2; i++) {
/* 48 */       int curPage_tmp = curPage + i;
/* 49 */       if (curPage_tmp > totalPage) {
/*    */         break;
/*    */       }
/* 52 */       pagesBuffer.append("<span class=\"page-number\"><a href=\"" + url + "page/" + curPage_tmp + "/\">" + curPage_tmp + "</a></span>");
/* 53 */       showPages_now++;
/* 54 */       showPages_max = curPage_tmp;
/*    */     }
/* 56 */     while (showPages - showPages_now > 0) {
/* 57 */       showPages_max++;
/* 58 */       if (showPages_max > totalPage) {
/*    */         break;
/*    */       }
/* 61 */       pagesBuffer.append("<span class=\"page-number\"><a href=\"" + url + "page/" + showPages_max + "/\">" + showPages_max + "</a></span>");
/* 62 */       showPages_now++;
/*    */     }
/* 64 */     while (showPages - showPages_now > 0) {
/* 65 */       showPages_min--;
/* 66 */       if (showPages_min < 1) {
/*    */         break;
/*    */       }
/* 69 */       pagesBuffer.insert(0, "<span class=\"page-number\"><a href=\"" + url + "page/" + showPages_min + "/\">" + showPages_min + "</a></span>");
/* 70 */       showPages_now++;
/*    */     }
/*    */ 
/* 73 */     strBuf.append(pagesBuffer);
/*    */ 
/* 75 */     if (hasNextPage)
/* 76 */       strBuf.append("<span class=\"page-number\"><a href=\"" + url + "page/" + (curPage + 1) + "/\">next</a></span>");
/*    */     else {
/* 78 */       strBuf.append("<span class=\"page-number\" style=\"background-color:#ccc;\">next</span>");
/*    */     }
/* 80 */     strBuf.append("</nav>");
/* 81 */     return strBuf.toString();
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\s2mBlog.zip
 * Qualified Name:     s2mBlog-3.0.0.WEB-INF.classes.cc.s2m.web.s2mBlog.freemarker.PageBar
 * JD-Core Version:    0.6.1
 */